package me.lxw.blogsystem.domain;

import java.util.List;

/**
 * 分页模型类
 * 
 * @author 梁兴威
 * 
 * @param <T>
 */
public class Page<T> {
    private int pageSize = 6; // 每页显示条数
    private int totalCount; // 总条数
    private int start; // 开始条数
    private int pageNo = 1;// 当前页
    private int totalPages; // 总页数
    private List<T> data;// 数据

    public Page(int pageNo) {
        if (pageNo < 1) {
            pageNo = 1;
        }
        this.pageNo = pageNo;
    }

    public Page(int pageNo, int pageSize) {
        if (pageNo < 1) {
            pageNo = 1;
        }
        this.pageNo = pageNo;
        this.pageSize = pageSize;
    }

    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;

        int totalPages = totalCount / pageSize;

        if (totalCount % pageSize != 0) {
            totalPages++;
        }

        this.totalPages = totalPages;
    }

    public int getStart() {
        this.start = (pageNo - 1) * pageSize;
        return this.start;
    }

    public int getTotalCount() {
        return this.totalCount;
    }

    public int getTotalPages() {
        return this.totalPages;
    }

    public boolean getHasNextPage() {
        return pageNo < totalPages;
    }

    public boolean getHasPrevPage() {
        return pageNo > 1;
    }

    public int getPageSize() {
        return pageSize;
    }

    public List<T> getData() {
        return data;
    }

    public void setData(List<T> data) {
        this.data = data;
    }

    public int getPageNo() {
        return pageNo;
    }

}